package com.example.home.loveDonation.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.loveDonation.activity.BenefitActivity;
import com.example.home.loveDonation.bean.BenefitListBean;

import java.util.List;

import static com.example.home.tool.StaticActi.ip;

public class WelfareclassificationApter extends RecyclerView.Adapter<WelfareclassificationApter.MyHoldy> {
    private Context context;
    private List<BenefitListBean.DataBean> list;
    private View view;

    public WelfareclassificationApter(Context context, List<BenefitListBean.DataBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHoldy onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.item_sever,null);
        return new MyHoldy(view);
    }


    @Override
    public void onBindViewHolder(@NonNull MyHoldy holder, int position) {
        Glide.with(context).load(ip+list.get(position).getImgUrl()).into(holder.sever_tv_img);
        holder.sever_iv_text.setText(list.get(position).getName());
        holder.rootView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, BenefitActivity.class);
                intent.putExtra("welf_id",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list == null ? 0 : list.size();
    }

    public class MyHoldy extends RecyclerView.ViewHolder {

        private final TextView sever_iv_text;
        private final ImageView sever_tv_img;
        private final LinearLayout rootView;

        public MyHoldy(@NonNull View itemView) {
            super(itemView);
            sever_iv_text = itemView.findViewById(R.id.sever_iv_text);
            sever_tv_img = itemView.findViewById(R.id.sever_tv_img);
            rootView = itemView.findViewById(R.id.rootView);
        }
    }
}
